﻿

using System;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Xc.DataAccess.Core;
using Xc.DataAccess.AepCoapCore.Models;
using Xc.DataAccess.AepCoapCore.Models.Apis;
using Xc.Logics.AepCoap.Models;
using Xc.DataAccess.Core.Services;

namespace Lzkj.AepCoapCore
{
    /// <summary>
    /// AEPCoap 服务
    /// </summary>
    public class AepCoapService : IAepCoapService
    {
        private readonly IConverterService converterService;

        public AepCoapService(IConverterService converterService)
        {
            this.converterService = converterService;
        }
        #region 产品管理
        /// <summary>
        /// 查询产品
        /// </summary>
        /// <returns></returns>
        public string QueryProduct(QueryProduct queryProduct)
        {
            var res = Aep_product.ProductGetInfo(queryProduct.AppKey, queryProduct.AppSecret, queryProduct.ProductId.ToString(), queryProduct.MasterId);
            return res;
        }

        /// <summary>
        /// 查询产品列表
        /// </summary>
        /// <returns></returns>
        public string QueryProductList(QueryProductList queryProduct)
        {
            var res = Aep_product_management.QueryProductList(queryProduct.AppKey, queryProduct.AppSecret, queryProduct.SearchValue, queryProduct.PageNow.ToString(), queryProduct.PageSize.ToString());
            return res;
        }
        /// <summary>
        /// 删除产品
        /// </summary>
        /// <returns></returns>
        public string DeleteProduct(DeleteProduct deleteProduct)
        {
            var res = Aep_product_management.DeleteProduct(deleteProduct.AppKey, deleteProduct.AppSecret, deleteProduct.MasterKey, deleteProduct.ProductId);
            return res;
        }
        /// <summary>
        /// 创建产品
        /// </summary>
        /// <returns></returns>
        public string CreateProduct<TBody>(AepInfoBasicBody<TBody> aepProduct)
        {
            var res = Aep_product_management.CreateProduct(aepProduct.AppKey, aepProduct.AppSecret, aepProduct.BodyString);
            return res;
        }
        /// <summary>
        /// 更新产品
        /// </summary>
        /// <returns></returns>
        public string UpdateProduct<TBody>(AepInfoBasicBody<TBody> aepProduct)
        {
            var res = Aep_product_management.UpdateProduct(aepProduct.AppKey, aepProduct.AppSecret, aepProduct.BodyString);
            return res;
        }

        #endregion

        #region 设备管理

        /// <summary>
        /// 产品设备列表信息
        /// </summary>
        /// <returns></returns>
        public async Task<ResultData<GetDeviceListModel>> QueryDeviceList(QueryDeviceList queryDeviceList)
        {
           return await Task.Run(() => 
           {
                var res = Aep_device_management.QueryDeviceList(queryDeviceList.AppKey, queryDeviceList.AppSecret, queryDeviceList.MasterKey, queryDeviceList.ProductId.ToString(), queryDeviceList.SearchValue, queryDeviceList.PageNow.ToString(), queryDeviceList.PageSize.ToString());
               if (string.IsNullOrEmpty(res))
               {
                   return ResultData<GetDeviceListModel>.Reject("无有效的数据", null);
               }
               else
               {
                   return ResultData<GetDeviceListModel>.Accept("解析成功", converterService.FromJsonString<GetDeviceListModel>(res));
               }
           });
        }
        /// <summary>
        /// 获取单个设备详情
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="deviceId"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        public string QueryDevice(QueryDevice queryDevice)
        {
            var res = Aep_device_management.QueryDevice(queryDevice.AppKey, queryDevice.AppSecret, queryDevice.MasterKey, queryDevice.DeviceId, queryDevice.ProductId.ToString());
            return res;
        }
        /// <summary>
        /// 删除设备
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="productId"></param>
        /// <param name="deviceIds"></param>
        /// <returns></returns>
        public string DeleteDevice(DeleteDevice deleteDevice)
        {
            var res = Aep_device_management.DeleteDevice(deleteDevice.AppKey, deleteDevice.AppSecret, deleteDevice.MasterKey, deleteDevice.ProductId.ToString(), deleteDevice.DevcieIds);
            return res;
        }

        /// <summary>
        /// 更新设备
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="deviceId"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public async Task<ResultData<UpdateDeviceRespon>> UpdateDevice<TBody>(UpdateDevcie<TBody> updateDevcie)
        {
           return await Task.Run(() => {
                var res = Aep_device_management.UpdateDevice(updateDevcie.AppKey, updateDevcie.AppSecret, updateDevcie.MasterKey, updateDevcie.DevcieId, updateDevcie.BodyString);
                if (string.IsNullOrEmpty(res))
                {
                    return ResultData<UpdateDeviceRespon>.Reject("无有效的数据", null);
                }
                return ResultData<UpdateDeviceRespon>.Accept("解析成功", converterService.FromJsonString<UpdateDeviceRespon>(res));
            });
        }
        /// <summary>
        /// 添加设备
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public async Task<ResultData<AddDeviceRespond>> CreateDeviceAsync<TBody>(BodyDevcie<TBody> createDevcie)
        {
           return await Task.Run(() => {
                var res = Aep_device_management.CreateDevice(createDevcie.AppKey, createDevcie.AppSecret, createDevcie.MasterKey, createDevcie.BodyString);
                if (string.IsNullOrEmpty(res))
                {
                    return ResultData<AddDeviceRespond>.Reject("无有效的数据", null);
                }
                return ResultData<AddDeviceRespond>.Accept("解析成功", converterService.FromJsonString<AddDeviceRespond>(res));
            });
        }
        /// <summary>
        /// 绑定设备
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string BindDevice<TBody>(BodyDevcie<TBody> createDevcie)
        {
            var res = Aep_device_management.BindDevice(createDevcie.AppKey, createDevcie.AppSecret, createDevcie.MasterKey, createDevcie.BodyString);
            return res;
        }
        /// <summary>
        /// 解除绑定
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>

        public string UnbindDevice<TBody>(BodyDevcie<TBody> createDevcie)
        {
            var res = Aep_device_management.UnbindDevice(createDevcie.AppKey, createDevcie.AppSecret, createDevcie.MasterKey, createDevcie.BodyString);
            return res;
        }
        /// <summary>
        /// 根据IMEI号查询信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="imei"></param>
        /// <returns></returns>
        public string QueryProductInfoByImei(ImeiInfo imeiInfo)
        {
            var res = Aep_device_management.QueryProductInfoByImei(imeiInfo.AppKey, imeiInfo.AppSecret, imeiInfo.Imei);
            return res;
        }


        public string BatchCreateNBDevice(string appKey, string appSecret, string body, string MasterKey)
        {
            var res = Aep_nb_device_management.BatchCreateNBDevice(appKey, appSecret, body, MasterKey);
            return res;
        }

        #endregion

        #region 指令下发
        /// <summary>
        /// 使用profile的下发指令
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string CreateCommandLwm2mProfile<Tbody>(MasterKeyInfo<Tbody> masterKeyInfo)
        {
            var res = Aep_device_command_lwm_profile.CreateCommandLwm2mProfile(masterKeyInfo.AppKey, masterKeyInfo.AppSecret, masterKeyInfo.BodyString, masterKeyInfo.MasterKey);
            return res;
        }
        /// <summary>
        /// 不使用profile的创建指令
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string CreateCommand<Tbody>(MasterKeyInfo<Tbody> masterKeyInfo)
        {
            var res = Aep_device_command.CreateCommand(masterKeyInfo.AppKey, masterKeyInfo.AppSecret, masterKeyInfo.MasterKey, masterKeyInfo.BodyString);
            return res;
        }
        /// <summary>
        /// 获取设备指令列表
        /// </summary>
        /// <returns></returns>
        public string QueryCommandList(QueryCommandList queryCommandList)
        {
            var res = Aep_device_command.QueryCommandList(queryCommandList.AppKey, queryCommandList.AppSecret, queryCommandList.MasterKey, queryCommandList.ProductId, queryCommandList.SearchValue, queryCommandList.DeviceId, queryCommandList.Status, queryCommandList.StartTime.ToDateTimeString(), queryCommandList.EndTime.ToDateTimeString(), queryCommandList.PageNow?.ToString(), queryCommandList.PageSize?.ToString(), queryCommandList.GroupCommandId);
            return res;
        }
        /// <summary>
        /// 查询单条指令
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="commandId"></param>
        /// <param name="productId"></param>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public string QueryCommand(string appKey, string appSecret, string MasterKey, string commandId, string productId, string deviceId = "")
        {
            var res = Aep_device_command.QueryCommand(appKey, appSecret, MasterKey, commandId, productId, deviceId);
            return res;
        }
        /// <summary>
        /// 取消指令
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string CancelCommand(string appKey, string appSecret, string MasterKey, string body)
        {
            var res = Aep_device_command.CancelCommand(appKey, appSecret, MasterKey, body);
            return res;
        }



        #endregion

        #region 数据查询

        /// <summary>
        /// 终端单个最新状态查询接口
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string QueryDeviceStatus(string appKey, string appSecret, string body)
        {
            var res = Aep_device_status.QueryDeviceStatus(appKey, appSecret, body);
            return res;
        }
        /// <summary>
        /// 批量获取设备最新状态数据
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string QueryDeviceStatusList(string appKey, string appSecret, string body)
        {
            var res = Aep_device_status.QueryDeviceStatusList(appKey, appSecret, body);
            return res;
        }
        /// <summary>
        /// 数据总数获取
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string GetDeviceStatusHisInTotal(string appKey, string appSecret, string body)
        {
            var res = Aep_device_status.getDeviceStatusHisInTotal(appKey, appSecret, body);
            return res;
        }
        /// <summary>
        /// 设备状态历史数据分页查询  获取历史数据
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string GetDeviceStatusHisInPage(string appKey, string appSecret, string body)
        {
            var res = Aep_device_status.getDeviceStatusHisInPage(appKey, appSecret, body);
            return res;
        }
        #endregion


        #region 物模型
        /// <summary>
        /// 查属性
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="productId"></param>
        /// <param name="searchValue"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public string QueryPropertyList(string appKey, string appSecret, string MasterKey, string productId, string searchValue = "", string pageNow = "", string pageSize = "")
        {
            var result = Aep_device_model.QueryPropertyList(appKey, appSecret, MasterKey, productId, searchValue, pageNow, pageSize);
            return result;
        }
        /// <summary>
        /// 查定义的服务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="productId"></param>
        /// <param name="searchValue"></param>
        /// <param name="serviceType"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>

        public string QueryServiceList(string appKey, string appSecret, string MasterKey, string productId, string searchValue = "", string serviceType = "", string pageNow = "", string pageSize = "")
        {
            var result = Aep_device_model.QueryServiceList(appKey, appSecret, MasterKey, productId, searchValue, serviceType, pageNow, pageSize);
            return result;
        }




        #endregion


        #region 规则引擎
        /// <summary>
        /// Saas规则引擎创建
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static string SaasCreateRule(string appKey, string appSecret, string body)
        {
            var result = Aep_rule_engine.saasCreateRule(appKey, appSecret, body);
            return result;

        }
        //参数ruleId: 类型String, 参数可以为空
        //  描述:
        //参数productId: 类型String, 参数可以为空
        //  描述:
        //参数pageNow: 类型long, 参数可以为空
        //  描述:
        //参数pageSize: 类型long, 参数可以为空
        //  描述:
        /// <summary>
        /// 查询规则
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="ruleId"></param>
        /// <param name="productId"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static string SaasQueryRule(string appKey, string appSecret, string ruleId = "", string productId = "", string pageNow = "", string pageSize = "")
        {
            var result = Aep_rule_engine.saasQueryRule(appKey, appSecret, ruleId, productId, pageNow, pageSize);
            return result;
        }
        //参数body: 类型json, 参数不可以为空
        //  描述:body,具体参考平台api说明
        /// <summary>
        /// 更新规则
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static string SaasUpdateRule(string appKey, string appSecret, string body)
        {
            var result = Aep_rule_engine.saasUpdateRule(appKey, appSecret, body);
            return result;
        }
        //参数body: 类型json, 参数不可以为空
        //  描述:body,具体参考平台api说明
        /// <summary>
        /// 删除规则
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static string SaasDeleteRuleEngine(string appKey, string appSecret, string body)
        {
            var result = Aep_rule_engine.saasDeleteRuleEngine(appKey, appSecret, body);
            return result;
        }

        #endregion

        #region 消息订阅
        /// <summary>
        /// 查询单个订阅
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="subId"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string GetSubscription(string appKey, string appSecret, string subId, string productId, string MasterKey)
        {
            var result = Aep_subscribe_north.GetSubscription(appKey, appSecret, subId, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 获取订阅列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="MasterKey"></param>
        /// <param name="subType"></param>
        /// <param name="searchValue"></param>
        /// <returns></returns>
        public string GetSubscriptionsList(string appKey, string appSecret, string productId, string pageNow, string pageSize, string MasterKey, string subType = "", string searchValue = "")
        {
            var result = Aep_subscribe_north.GetSubscriptionsList(appKey, appSecret, productId, pageNow, pageSize, MasterKey, subType, searchValue);
            return result;
        }
        /// <summary>
        /// 删除订阅
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="subId">订阅ID</param>
        /// <param name="productId"></param>
        /// <param name="subLevel">订阅级别,必填(1:产品级 2：设备级)</param>
        /// <param name="MasterKey"></param>
        /// <param name="deviceId">设备id(产品级可以不填,设备级必填),</param>
        /// <returns></returns>
        public string DeleteSubscription(string appKey, string appSecret, string subId, string productId, string subLevel, string MasterKey, string deviceId = "")
        {
            var result = Aep_subscribe_north.DeleteSubscription(appKey, appSecret, subId, productId, subLevel, MasterKey, deviceId);
            return result;
        }
        /// <summary>
        /// 添加订阅
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// 
        ///body {
        //  "deviceId": "String",
        //  "operator": "String",
        //  "productId": int,
        //  "subLevel": int,
        //  "subTypes":int[],
        //  "subUrl": "String"
        //}
        /// 
        /// <returns></returns>
        public string CreateSubscription(string appKey, string appSecret, string MasterKey, string body)
        {
            var result = Aep_subscribe_north.CreateSubscription(appKey, appSecret, MasterKey, body);
            return result;
        }
        #endregion


        #region 公共产品管理
        /// <summary>
        /// 根据私有产品ID查询公共产品信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string QueryPublicByPublicProductId(string appKey, string appSecret, string body)
        {
            var result = Aep_public_product_management.QueryPublicByPublicProductId(appKey, appSecret, body);
            return result;
        }
        /// <summary>
        /// 根据公共产品ID查询公共产品信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string QueryPublicByProductId(string appKey, string appSecret, string body)
        {
            var result = Aep_public_product_management.QueryPublicByProductId(appKey, appSecret, body);
            return result;
        }


        #endregion


        #region 固件管理
        /// <summary>
        /// 更新固件
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id">固件</param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>id
        /// <returns></returns>
        public string UpdateFirmware(string appKey, string appSecret, string id, string body, string MasterKey = "")
        {
            var result = Aep_firmware_management.UpdateFirmware(appKey, appSecret, id, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询固件列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="searchValue"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryFirmwareList(string appKey, string appSecret, string productId, string searchValue = "", string pageNow = "", string pageSize = "", string MasterKey = "")
        {
            var result = Aep_firmware_management.QueryFirmwareList(appKey, appSecret, productId, searchValue, pageNow, pageSize, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询固件
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryFirmware(string appKey, string appSecret, string id, string productId, string MasterKey = "")
        {
            var result = Aep_firmware_management.QueryFirmware(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 删除固件
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="updateBy"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string DeleteFirmware(string appKey, string appSecret, string id, string productId, string updateBy = "", string MasterKey = "")
        {
            var result = Aep_firmware_management.DeleteFirmware(appKey, appSecret, id, productId, updateBy, MasterKey);
            return result;
        }


        #endregion


        #region 固件远程升级管理
        /// <summary>
        /// 查询主任务详情统计
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryRemoteUpgradeDetail(string appKey, string appSecret, string id, string productId, string MasterKey = "")
        {
            var result = Aep_upgrade_management.QueryRemoteUpgradeDetail(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询任务详情基本信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id">主任务id</param>
        /// <param name="productId">产品id</param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryRemoteUpgradeTask(string appKey, string appSecret, string id, string productId, string MasterKey = "")
        {
            var result = Aep_upgrade_management.QueryRemoteUpgradeTask(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 主任务执行控制(启动主任务开始升级)
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string ControlRemoteUpgradeTask(string appKey, string appSecret, string id, string body, string MasterKey = "")
        {
            var result = Aep_upgrade_management.ControlRemoteUpgradeTask(appKey, appSecret, id, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询可升级设备列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="isSelectDevice">查询类型（1.查询加入升级设备，2.查询可加入升级设备）</param>
        /// <param name="id">主任务id,isSelectDevice为1时必填，为2不必填</param>
        /// <param name="pageNow">当前页，默认1</param>
        /// <param name="pageSize">每页显示数，默认20</param>
        /// <param name="MasterKey"></param>
        /// <param name="deviceIdSearch">根据设备id精确查询</param>
        /// <param name="deviceNameSearch">根据设备名称精确查询</param>
        /// <param name="imeiSearch">根据imei号精确查询，仅支持LWM2M协议</param>
        /// <param name="deviceNoSearch">根据设备编号精确查询，仅支持T_Link协议</param>
        /// <param name="deviceGroupIdSearch">根据群组id精确查询</param>
        /// <returns></returns>
        public string QueryRemoteUpradeDeviceList(string appKey, string appSecret, string productId, string isSelectDevice, string id = "", string pageNow = "", string pageSize = "", string MasterKey = "", string deviceIdSearch = "", string deviceNameSearch = "", string imeiSearch = "", string deviceNoSearch = "", string deviceGroupIdSearch = "")
        {
            var result = Aep_upgrade_management.QueryRemoteUpradeDeviceList(appKey, appSecret, productId, isSelectDevice, id, pageNow, pageSize, MasterKey, deviceIdSearch, deviceNameSearch, imeiSearch, deviceNoSearch, deviceGroupIdSearch);
            return result;
        }
        /// <summary>
        /// 删除远程升级主任务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="updateBy"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string DeleteRemoteUpgradeTask(string appKey, string appSecret, string id, string productId, string updateBy = "", string MasterKey = "")
        {
            var result = Aep_upgrade_management.DeleteRemoteUpgradeTask(appKey, appSecret, id, productId, updateBy, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询升级主任务列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="MasterKey"></param>
        /// <param name="searchValue"></param>
        /// <returns></returns>
        public string QueryRemoteUpgradeTaskList(string appKey, string appSecret, string productId, string pageNow = "", string pageSize = "", string MasterKey = "", string searchValue = "")
        {
            var result = Aep_upgrade_management.QueryRemoteUpgradeTaskList(appKey, appSecret, productId, pageNow, pageSize, MasterKey, searchValue);
            return result;
        }
        /// <summary>
        /// 修改远程升级主任务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string ModifyRemoteUpgradeTask(string appKey, string appSecret, string id, string body, string MasterKey = "")
        {
            var result = Aep_upgrade_management.ModifyRemoteUpgradeTask(appKey, appSecret, id, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 创建远程升级主任务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string CreateRemoteUpgradeTask(string appKey, string appSecret, string body, string MasterKey = "")
        {
            var result = Aep_upgrade_management.CreateRemoteUpgradeTask(appKey, appSecret, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 操作远程升级主任务（包括设备升级，取消升级，重试升级）
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string OperationalRemoteUpgradeTask(string appKey, string appSecret, string body, string MasterKey = "")
        {
            var result = Aep_upgrade_management.OperationalRemoteUpgradeTask(appKey, appSecret, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询任务详情子任务列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="taskStatus">很多种，见文档</param>
        /// <param name="searchValue">查询值，设备ID或设备编号(IMEI)或设备名称模糊查询</param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryRemoteUpgradeSubtasks(string appKey, string appSecret, string id, string productId, string taskStatus = "", string searchValue = "", string pageNow = "", string pageSize = "", string MasterKey = "")
        {
            var result = Aep_upgrade_management.QueryRemoteUpgradeSubtasks(appKey, appSecret, id, productId, taskStatus, searchValue, pageNow, pageSize, MasterKey);
            return result;
        }
        #endregion

        #region 分组管理
        /// <summary>
        /// 新增分组
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string CreateDeviceGroup(string appKey, string appSecret, string body, string MasterKey = "")
        {
            var result = Aep_device_group_management.CreateDeviceGroup(appKey, appSecret, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 更新分组
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string UpdateDeviceGroup(string appKey, string appSecret, string body, string MasterKey = "")
        {
            var result = Aep_device_group_management.UpdateDeviceGroup(appKey, appSecret, body, MasterKey);
            return result;
        }
        /// <summary>
        /// 删除分组
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="deviceGroupId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string DeleteDeviceGroup(string appKey, string appSecret, string productId, string deviceGroupId, string MasterKey = "")
        {
            var result = Aep_device_group_management.DeleteDeviceGroup(appKey, appSecret, productId, deviceGroupId, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询分组列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="searchValue"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QueryDeviceGroupList(string appKey, string appSecret, string productId, string pageNow, string pageSize, string searchValue = "", string MasterKey = "")
        {
            var result = Aep_device_group_management.QueryDeviceGroupList(appKey, appSecret, productId, pageNow, pageSize, searchValue, MasterKey);
            return result;
        }
        /// <summary>
        /// 编辑分组与设备关联关系
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="body"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string UpdateDeviceGroupRelation(string appKey, string appSecret, string body, string MasterKey = "")
        {
            var result = Aep_device_group_management.UpdateDeviceGroupRelation(appKey, appSecret, body, MasterKey);
            return result;
        }
        #endregion

        #region 标准物模型
        /// <summary>
        /// 标准物模型查询
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="thirdType">三级分类id</param>
        /// <param name="standardVersion">标准物模型版本号</param>
        /// <returns></returns>
        public string QueryStandardModel(string appKey, string appSecret, string thirdType, string standardVersion = "")
        {
            var result = Aep_standard_management.QueryStandardModel(appKey, appSecret, thirdType, standardVersion);
            return result;
        }
        #endregion

        #region 软件升级包管理
        /// <summary>
        /// 修改升级包信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static string UpdateSoftware(string appKey, string appSecret, string id, string MasterKey, string body)
        {
            var result = Aep_software_management.UpdateSoftware(appKey, appSecret, id, MasterKey, body);
            return result;
        }
        /// <summary>
        /// 删除升级包
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public static string DeleteSoftware(string appKey, string appSecret, string id, string productId, string MasterKey)
        {
            var result = Aep_software_management.DeleteSoftware(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询软件包详情
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public static string QuerySoftware(string appKey, string appSecret, string id, string productId, string MasterKey)
        {
            var result = Aep_software_management.QuerySoftware(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询升级包列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <param name="searchValue"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static string QuerySoftwareList(string appKey, string appSecret, string productId, string MasterKey, string searchValue = "", string pageNow = "", string pageSize = "")
        {
            var result = Aep_software_management.QuerySoftwareList(appKey, appSecret, productId, MasterKey, searchValue, pageNow, pageSize);
            return result;
        }
        #endregion

        #region 软件远程升级管理
        /// <summary>
        /// 主任务执行控制(启动主任务开始升级)
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string OperationalSoftwareUpgradeTask(string appKey, string appSecret, string MasterKey, string body)
        {
            var result = Aep_software_upgrade_management.OperationalSoftwareUpgradeTask(appKey, appSecret, MasterKey, body);
            return result;
        }
        /// <summary>
        /// 查询软件升级详情子任务列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <param name="taskStatus"></param>
        /// <param name="searchValue"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public string QuerySoftwareUpgradeSubtasks(string appKey, string appSecret, string id, string productId, string MasterKey, string taskStatus = "", string searchValue = "", string pageNow = "", string pageSize = "")
        {
            var result = Aep_software_upgrade_management.QuerySoftwareUpgradeSubtasks(appKey, appSecret, id, productId, MasterKey, taskStatus, searchValue, pageNow, pageSize);
            return result;
        }
        /// <summary>
        /// 查询任务详情基本信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QuerySoftwareUpgradeTask(string appKey, string appSecret, string id, string productId, string MasterKey)
        {
            var result = Aep_software_upgrade_management.QuerySoftwareUpgradeTask(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 创建远程软件升级主任务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string CreateSoftwareUpgradeTask(string appKey, string appSecret, string MasterKey, string body)
        {
            var result = Aep_software_upgrade_management.CreateSoftwareUpgradeTask(appKey, appSecret, MasterKey, body);
            return result;
        }
        /// <summary>
        /// 修改软件升级主任务信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string ModifySoftwareUpgradeTask(string appKey, string appSecret, string id, string MasterKey, string body)
        {
            var result = Aep_software_upgrade_management.ModifySoftwareUpgradeTask(appKey, appSecret, id, MasterKey, body);
            return result;
        }
        /// <summary>
        /// 主任务执行控制(启动主任务开始升级)
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="MasterKey"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string ControlSoftwareUpgradeTask(string appKey, string appSecret, string id, string MasterKey, string body)
        {
            var result = Aep_software_upgrade_management.ControlSoftwareUpgradeTask(appKey, appSecret, id, MasterKey, body);

            return result;
        }
        /// <summary>
        /// 删除软件升级主任务
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <param name="updateBy"></param>
        /// <returns></returns>
        public string DeleteSoftwareUpgradeTask(string appKey, string appSecret, string id, string productId, string MasterKey, string updateBy = "")
        {
            var result = Aep_software_upgrade_management.DeleteSoftwareUpgradeTask(appKey, appSecret, id, productId, MasterKey, updateBy);
            return result;
        }
        /// <summary>
        /// 查询可升级设备列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="isSelectDevice"></param>
        /// <param name="MasterKey"></param>
        /// <param name="id"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="deviceIdSearch"></param>
        /// <param name="deviceNameSearch"></param>
        /// <param name="imeiSearch"></param>
        /// <param name="deviceGroupIdSearch"></param>
        /// <returns></returns>
        public string QuerySoftwareUpradeDeviceList(string appKey, string appSecret, string productId, string isSelectDevice, string MasterKey, string id = "", string pageNow = "", string pageSize = "", string deviceIdSearch = "", string deviceNameSearch = "", string imeiSearch = "", string deviceGroupIdSearch = "")
        {
            var result = Aep_software_upgrade_management.QuerySoftwareUpradeDeviceList(appKey, appSecret, productId, isSelectDevice, MasterKey, id, pageNow, pageSize, deviceIdSearch, deviceNameSearch, imeiSearch, deviceGroupIdSearch);
            return result;
        }
        /// <summary>
        /// 查询主任务详情统计
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="id"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <returns></returns>
        public string QuerySoftwareUpgradeDetail(string appKey, string appSecret, string id, string productId, string MasterKey)
        {
            var result = Aep_software_upgrade_management.QuerySoftwareUpgradeDetail(appKey, appSecret, id, productId, MasterKey);
            return result;
        }
        /// <summary>
        /// 查询升级主任务列表
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        /// <param name="productId"></param>
        /// <param name="MasterKey"></param>
        /// <param name="pageNow"></param>
        /// <param name="pageSize"></param>
        /// <param name="searchValue"></param>
        /// <returns></returns>
        public string QuerySoftwareUpgradeTaskList(string appKey, string appSecret, string productId, string MasterKey, string pageNow = "", string pageSize = "", string searchValue = "")
        {
            var result = Aep_software_upgrade_management.QuerySoftwareUpgradeTaskList(appKey, appSecret, productId, MasterKey, pageNow, pageSize, searchValue);
            return result;
        }
        #endregion
    }
}
